#include"../../include/device/device.hpp"

#include<vector>
#include<iostream>


using namespace std;


namespace SoftEngine{

    // 对单个点进行旋转，直接修改点的坐标
void VirtualGPU::rotateSingleDot(XMFLOAT3& dot, XMFLOAT3 rotation, XMFLOAT3 position) {
    float radiansX = rotation.x * 3.1415926f / 180.0f;
    float radiansY = rotation.y * 3.1415926f / 180.0f;
    float radiansZ = rotation.z * 3.1415926f / 180.0f;
    
    // 计算各轴的旋转矩阵
    // X轴旋转矩阵
    MyMatrix xRotMatrix(
        XMFLOAT3(1.0f, 0.0f, 0.0f),
        XMFLOAT3(0.0f, cos(radiansX), sin(radiansX)),
        XMFLOAT3(0.0f, -sin(radiansX), cos(radiansX))
    );
    
    // Y轴旋转矩阵
    MyMatrix yRotMatrix(
        XMFLOAT3(cos(radiansY), 0.0f, sin(radiansY)),
        XMFLOAT3(0.0f, 1.0f, 0.0f),
        XMFLOAT3(-sin(radiansY), 0.0f, cos(radiansY))
    );
    
    // Z轴旋转矩阵
    MyMatrix zRotMatrix(
        XMFLOAT3(cos(radiansZ), -sin(radiansZ), 0.0f),
        XMFLOAT3(sin(radiansZ), cos(radiansZ), 0.0f),
        XMFLOAT3(0.0f, 0.0f, 1.0f)
    );
    
    // 以position为中心进行旋转
    XMFLOAT3 centeredDot(
        dot.x - position.x,
        dot.y - position.y,
        dot.z - position.z
    );
    
    // 依次应用各轴的旋转矩阵
    XMFLOAT3 rotatedDot = centeredDot;
    rotatedDot = xRotMatrix * rotatedDot;
    rotatedDot = yRotMatrix * rotatedDot;
    rotatedDot = zRotMatrix * rotatedDot;
    
    // 将点移回原始坐标系并直接修改原点坐标
    dot.x = rotatedDot.x + position.x;
    dot.y = rotatedDot.y + position.y;
    dot.z = rotatedDot.z + position.z;
}

// 对所有点进行批量旋转
void VirtualGPU::dotRotation(vector<XMFLOAT3>& allDot, XMFLOAT3 rotation, XMFLOAT3 position) {
    for (int i = 0; i < allDot.size(); i++) {
        rotateSingleDot(allDot[i], rotation, position);
    }
}

}